#include "constraintswindow.h"
#include <iostream>

ConstraintsWindow::ConstraintsWindow(BaseObjectType* cobject,
									 const Glib::RefPtr<Gnome::Glade::Xml>& ui_xml)
	: Gtk::Dialog(cobject),
	  number_of_courses_spinbutton_(0),
	  cancel_button_(0),
	  ok_button_(0)
{
	// connect a handler to the delete-event signal, which is sent when the
	// user closes the window
	signal_delete_event().connect(
		sigc::mem_fun(*this, &ConstraintsWindow::on_delete_event));

	// initialize and set up child widgets
	ui_xml->get_widget("number_of_courses_spinbutton",
					   number_of_courses_spinbutton_);
	ui_xml->get_widget("cancel_button", cancel_button_);
	cancel_button_->signal_clicked().connect(
		sigc::mem_fun(*this, &ConstraintsWindow::on_cancel));
	ui_xml->get_widget("ok_button", ok_button_);
	ok_button_->signal_clicked().connect(
		sigc::mem_fun(*this, &ConstraintsWindow::on_ok));
}

ConstraintsWindow::~ConstraintsWindow()
{
}

/// Handler for the signal emitted when the user clicks the Cancel button.
void ConstraintsWindow::on_cancel()
{
	std::clog << "The Cancel button was clicked." << std::endl;
	hide();
	response(Gtk::RESPONSE_REJECT);
}

/// Handler for the signal emitted when the user clicks the Ok button.
void ConstraintsWindow::on_ok()
{
	std::clog << "The Ok button was clicked." << std::endl;
	hide();
	response(Gtk::RESPONSE_ACCEPT);
}

/// Handler for the signal emitted when the user closes the window.
bool ConstraintsWindow::on_delete_event(GdkEventAny*)
{
	on_cancel();
	return true;
}

int ConstraintsWindow::number_of_courses() const
{
	return number_of_courses_spinbutton_->get_value_as_int();
}
